package com.alorma.bcn.objects;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface.OnClickListener;

import com.alorma.bcn.listeners.CancelListener;

public class Dialogos {

	private Context ctx;
	private String message;
	private String title;
	private boolean botones;

	private AlertDialog.Builder builder;
	private String txtBtn1;
	private OnClickListener click1 = null;

	public Dialogos(Context ctx) {
		this.ctx = ctx;
	}

	public Dialogos(Context ctx, String title, String message, boolean botones) {
		this.ctx = ctx;
		this.title = title;
		this.message = message;
		this.botones = botones;
		this.txtBtn1 = "Ok";
	}

	private AlertDialog.Builder construirDialogo() {
		builder = new AlertDialog.Builder(this.ctx);

		builder.setTitle(title);
		builder.setMessage(message);
		if (click1 != null) {
			builder.setPositiveButton(this.txtBtn1, this.click1);
		} else {
			builder.setPositiveButton(this.txtBtn1, new CancelListener(
					(Activity) this.ctx));
		}
		if (this.botones) {
			builder.setNegativeButton("Cancelar", new CancelListener(
					(Activity) this.ctx));
		}

		return builder;
	}

	public void setBtn1(int txt) {
		this.txtBtn1 = this.ctx.getResources().getString(txt);

	}

	public void setBtn1(String txt) {
		this.txtBtn1 = txt;
	}

	public void setBtn1(String txt, OnClickListener click) {
		this.txtBtn1 = txt;
		this.click1 = click;
	}

	public void setBtn1(int txt, OnClickListener click) {
		this.txtBtn1 = this.ctx.getResources().getString(txt);
		;
		this.click1 = click;
	}

	public void setTitle(String txt) {
		this.title = txt;
	}

	public void setMessage(String txt) {
		this.message = txt;
	}

	public void setTitle(int txt) {
		this.title = this.ctx.getResources().getString(txt);
	}

	public void setMessage(int txt) {
		this.message = this.ctx.getResources().getString(txt);
	}

	public void set2Buttons(Boolean btns) {
		this.botones = btns;
	}

	public AlertDialog mostrarDialogo() {
		return this.construirDialogo().show();
	}

	public AlertDialog mostrarDialogo(String tit, String txt) {
		setTitle(tit);
		setMessage(txt);
		return this.construirDialogo().show();
	}
}
